package com.lablzh.gdxy.repository.practice;

import com.lablzh.gdxy.entity.practice.PracticeApply;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

public interface PracticeApplyRepository extends JpaRepository<PracticeApply, Integer> {

    PracticeApply findByStudentUsernameAndProjectID(String studentUsername, Integer projectID);

    @Modifying
    @Transactional
    @Query("update PracticeApply set status=?2 where id=?1")
    int updateStatusById(Integer id, String status);

    //    List<StudentID> findAllByProjectIDAndStatus(Integer id, String status);
    List<PracticeApply> findAllByTeacherAndId(String teacher, Integer id);

    List<PracticeApply> findAllByProjectID(Integer id);

    @Transactional
    void deleteByProjectID(Integer id);

    List<PracticeApply> findAllByStudentUsername(String username);

    List<PracticeApply> findAllByProjectIDAndStatus(Integer id, String status);

    int countAllByProjectIDAndStatus(Integer id, String status);

}
